package org.campuscontent.ui.multipanel;

import java.util.ResourceBundle;

import javax.swing.JTabbedPane;

import org.campuscontent.config.Config;
import org.campuscontent.config.languages.LanguageListener;
import org.campuscontent.config.languages.LanguageManager;
import org.campuscontent.ui.TemplateBase;
import org.campuscontent.ui.multipanel.UsersPanelManager.Entry;

public class UsersPanelContainer extends JTabbedPane implements LanguageListener
{
    public UsersPanelContainer( TemplateBase parent )
    {
        this.parent = parent;
        
        init();
    }
    
    protected void init()
    {
        LanguageManager lm = LanguageManager.getInstance();
        lm.addListener( this );
        
        UsersPanelManager upMng = UsersPanelManager.getInstance();
        Entry[] elements = upMng.elements();
        
        for ( Entry em : elements )
        {
            addTab( em.instance.label(), em.instance.parent() );
        }
        
        parent.mf.rootPanel.setDividerLocation(Config.ROOT_HEIGHT);
    }
    
    public void update( ResourceBundle resources )
    {
        UsersPanelManager upMng = UsersPanelManager.getInstance();
        Entry[] elements = upMng.elements();
        
        int i = 0;
        for ( Entry em : elements )
        {
            setTitleAt( i, em.instance.label() );
            i++;
        }
    }
    
    public void updateItems()
    {
        UsersPanelManager upMng = UsersPanelManager.getInstance();
        Entry[] elements = upMng.elements();
     
        removeAll();
        int i = 0;
        for ( Entry em : elements )
        {
            if ( em.state )
            {
                addTab( em.instance.label(), em.instance.parent() );
                i++;
            }
        }
    }
    
    protected TemplateBase parent;
}
